package com.mpgame.database.mysql.config;

import com.mpgame.database.constants.Constants;

import lombok.Data;

@Data
public class MySqlCfg {
    private String url;
    private String username;
    private String password;
    private String driverClassName;

    // HikariCP 连接池配置
    private int maximumPoolSize;
    private int minimumIdle;
    private long connectionTimeout;
    private long idleTimeout;
    private long maxLifetime;
    private String connectionTestQuery;
    private long validationTimeout;
    private long initializationFailTimeout;
    private long keepAliveTime;
    private long leakDetectionThreshold;

    public static MySqlCfg getDefault() {
        MySqlCfg config = new MySqlCfg();
        config.setUrl("jdbc:mysql://localhost:" + Constants.CMySQL.MYSQL_GAME_PORT + "/mp_game?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&maxReconnects=3&initialTimeout=2");
        config.setUsername(Constants.CMySQL.MYSQL_GAME_USER);
        config.setPassword(Constants.CMySQL.MYSQL_GAME_PWD);
        config.setDriverClassName("com.mysql.cj.jdbc.Driver");
        config.setMaximumPoolSize(20);
        config.setMinimumIdle(5);
        config.setConnectionTimeout(30000);
        config.setIdleTimeout(600000);
        config.setMaxLifetime(1800000);
        config.setConnectionTestQuery("SELECT 1");
        config.setValidationTimeout(5000);
        config.setInitializationFailTimeout(-1);
        config.setKeepAliveTime(30000);
        config.setLeakDetectionThreshold(60000);
        return config;
    }

    public static MySqlCfg getVerify() {
        MySqlCfg config = new MySqlCfg();
        config.setUrl("jdbc:mysql://localhost:" + Constants.CMySQL.MYSQL_VERIFY_PORT + "/mp_verify?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&maxReconnects=3&initialTimeout=2");
        config.setUsername(Constants.CMySQL.MYSQL_VERIFY_USER);
        config.setPassword(Constants.CMySQL.MYSQL_VERIFY_PWD);
        config.setDriverClassName("com.mysql.cj.jdbc.Driver");
        config.setMaximumPoolSize(20);
        config.setMinimumIdle(5);
        config.setConnectionTimeout(30000);
        config.setIdleTimeout(600000);
        config.setMaxLifetime(1800000);
        config.setConnectionTestQuery("SELECT 1");
        config.setValidationTimeout(5000);
        config.setInitializationFailTimeout(-1);
        config.setKeepAliveTime(30000);
        config.setLeakDetectionThreshold(60000);
        return config;
    }
}
